<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 200px;
            background-color: red;
        }
        span{
            position: absolute;
            top: 10px;
            left: 10px;
        }
    </style>
    <script>
        // e 事件对象
        window.onload=function(){
          var div=document.querySelector("div");
          var span=document.querySelector("span");
          div.onmousemove=function(e){
                // 获取鼠标位置  
                //  console.log(e.x,e.y);
                span.style.top=e.y+"px";
                span.style.left=e.x+"px";
          }
        }
    </script>
</head>
<body>
    <div></div>
    <span>这是一段文字</span>
</body>
</html>